package com.eastjet.equipment.controller;


import cn.hutool.http.server.HttpServerResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastjet.equipment.service.DeviceDeptService;
import com.eastjet.equipment.util.ExcelExportUtil;
import com.eastjet.maintenance.domain.DeviceDept;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeviceDeptService deviceDeptService;

    @RequestMapping("/list")
    public Page<DeviceDept> list(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "100") int size,
                                 @RequestParam(defaultValue ="") String condition)
    {
        System.out.println("condition:" + condition);
        return deviceDeptService.getDeviceDept(page, size,condition);
    }


    @RequestMapping("/test")
    public  String test(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int size,
            @RequestParam(defaultValue ="") String condition,
            @RequestParam(defaultValue = "") String filename,
             HttpServletResponse response
    )
    {
        System.out.println("进5619684656456564456456456456456456");
        Page<DeviceDept> pageData = deviceDeptService.getDeviceDept(page, size,condition);
        ExcelUtil<DeviceDept> util=new ExcelUtil<DeviceDept>(DeviceDept.class);
        util.exportExcel( response, pageData.getRecords(), "D:/file",filename);
//        System.out.println("pageData:" + pageData.getRecords());
//        ExcelExportUtil.exportToExcel(pageData.getRecords(), "D:/file", filename);
//        System.out.println("pppp");
        return "test";
    }


    @RequestMapping("/tests")
    public  String tests(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int size,
            @RequestParam(defaultValue ="") String condition,
            @RequestParam(defaultValue = "") String filename,
            HttpServletResponse response
    )
    {
        System.out.println("进5619684656456564456456456456456456");
        Page<DeviceDept> pageData = deviceDeptService.getDeviceDept(page, size,condition);
        ExcelUtil<DeviceDept> util=new ExcelUtil<DeviceDept>(DeviceDept.class);
        util.exportExcel( response, pageData.getRecords(), filename);
//        System.out.println("pageData:" + pageData.getRecords());
//        ExcelExportUtil.exportToExcel(pageData.getRecords(), "D:/file", filename);
//        System.out.println("pppp");  "D:/file",
        return "test";
    }
}
